package com.ruoyi.system.controller;

import java.sql.SQLException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.dto.ShipmentOrderDTO;
import com.ruoyi.system.vo.ShipmentOrderVO;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ShipmentOrder;
import com.ruoyi.system.service.IShipmentOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库单Controller
 * 
 * @author ruoyi
 * @date 2024-12-12
 */
@RestController
@RequestMapping("/wms/orders")
public class ShipmentOrderController extends BaseController
{
    @Autowired
    private IShipmentOrderService shipmentOrderService;

    /**
     * 查询出库单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShipmentOrderVO shipmentOrder)
    {
        startPage();
        List<ShipmentOrderDTO> list = shipmentOrderService.selectShipmentOrderList(shipmentOrder);
        System.out.println(list);
        return getDataTable(list);
    }


    /**
     * 导出出库单列表
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:export')")
    @Log(title = "出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShipmentOrderVO shipmentOrder)
    {
        List<ShipmentOrderDTO> list = shipmentOrderService.selectShipmentOrderList(shipmentOrder);
        ExcelUtil<ShipmentOrderDTO> util = new ExcelUtil<ShipmentOrderDTO>(ShipmentOrderDTO.class);
        util.exportExcel(response, list, "出库单数据");
    }

    /**
     * 获取出库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(shipmentOrderService.selectShipmentOrderById(id));
    }

    /**
     * 新增出库单
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:add')")
    @Log(title = "出库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShipmentOrderVO shipmentOrder) throws SQLException {
        return shipmentOrderService.insertShipmentOrder(shipmentOrder);
    }

    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShipmentOrderVO shipmentOrder) throws SQLException {
        return shipmentOrderService.updateShipmentOrder(shipmentOrder);
    }

    /**
     * 修改出库单
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:edit')")
    @Log(title = "出库单", businessType = BusinessType.UPDATE)
    @PostMapping("/ByShipmentOrderNo")
    public AjaxResult ByShipmentOrderNo(@RequestBody ShipmentOrderVO shipmentOrder) throws SQLException {
        return shipmentOrderService.updateShipmentOrderByShipmentOrderNo(shipmentOrder);
    }

    /**
     * 删除出库单
     */
    @PreAuthorize("@ss.hasPermi('wms:orders:remove')")
    @Log(title = "出库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable String id)
    {
        return toAjax(shipmentOrderService.deleteShipmentOrderByIds(id));
    }
}
